﻿namespace Corporation.Project.Controllers
{
    [AllowAnonymous]
    public class InitController : SiteApiControllerBase
    {
        private readonly UserManager<User> userManager;
        private readonly IIdentityContract identityContract;

        /// <summary>
        /// 测试控制器
        /// </summary>
        /// <param name="userManager"></param>
        /// <param name="identityContract"></param>
        public InitController(UserManager<User> userManager, IIdentityContract identityContract)
        {
            this.userManager = userManager;
            this.identityContract = identityContract;
        }

        [HttpGet]
        [UnitOfWork]
        [NonFunction]
        [Description("初始化用户")]
        public async Task<string> InitAdmin()
        {
            List<object> list = new List<object>();
            if (!userManager.Users.Any())
            {
                RegisterDto dto = new RegisterDto
                {
                    UserName = "admin",
                    Password = "admin@123",
                    NickName = "管理员",
                };

                OperationResult<User> result = await identityContract.Register(UserRegisterType.Neither, dto);
                if (result.Succeeded)
                {
                    User user = result.Data;
                    user.EmailConfirmed = true;
                    await userManager.UpdateAsync(user);
                }
            }

            return list.ExpandAndToString("\r\n");
        }

        [HttpPost]
        public string Test01()
        {
            var aaa = MicroCloud.Utils.I18N.T("测试01");
            return "aa";
        }
  
    }

}
